import time
from tpsThread import TpsThread


class WriteThread(TpsThread):
    def __init__(self, url, batch, tps=1):
        super(WriteThread, self).__init__(tps)
        self.__se = None
        self.__orders = MockOrders()

    def cbStart(self):
        self.__se = StorageEngine(url)
        
    def callback(self, curTransCnt):
        batch = curTransCnt
        orders = self.__orders.getBatch(batch)
        self.__se.executeBatch(batch, orders)
        print "hello world", curTransCnt

    def cbEnd(self):
        self.__se.close() 

def writeDataInBackgroud():
    wt = WriteThread(":memory", 3000)
    wt.start()
    time.sleep(2)
    wt.stop()

"""
def readThread():
    storageEngine = StorageEngine(url)

    secondPerRound = 1
    calc = CalcWaitTimeoutForFixInterval(secondPerRound)
    while True:
        calc.workStart()
        orders = storageEngine.fetchBatch(who, attributes, offset, count)
        calc.workEnd()
        waitTimeout = calc.calculate()
        if waitTimeout > 0:
            sleep(waitTimeout)
"""
